<template>
	<view class="verification-page" v-if="orderVerification">
		<u-navbar title="购课成功" bgColor="transparent" :autoBack="true" leftIconColor="#ffffff"
			titleStyle="color:#ffffff;">
		</u-navbar>
		<view class="verification-content" :style="{paddingTop:$u.addUnit(44 + $u.sys().statusBarHeight,'px')}">
			<view class="title">购买成功</view>
			<view class="small-title">感谢您的支持，满意的话记得常来哦</view>
			<view class="courses-box">
				<view class="courses-info">
					<view class="courses-left">
						<image class="image" :src="orderVerification.image"></image>
					</view>
					<view class="courses-right">
						<view class="courses-right-top">
							<view class="courses-name">{{orderVerification.name}}</view>
							<view class="courses-price">￥{{orderVerification.price}}</view>
						</view>
						<view class="courses-right-bottom">
							<view class="courses-coach">授课老师:{{orderVerification.teacher_name}}</view>
						</view>
					</view>
				</view>
				<!-- 核銷 -->
				<view class="please">
					<view class="perform">请到店进行核销</view>
					<image class="qrcode" :src="orderVerification.image_url"></image>
					<view class="VerCode">
						核销码：{{orderVerification.code}}
						<view class="copy" @click="handleCopy">复制</view>
					</view>
				</view>
				<view class="back" @click="handleBack">返回</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pre_id: null,
				orderVerification: null
			};
		},
		onLoad(options) {
			if (options && options.pre_id) {
				this.pre_id = options.pre_id
				this.orderPreoffInfo()
			}
		},
		methods: {
			orderPreoffInfo() {
				this.$Api.courses.orderPreoffInfo({
					pre_id: this.pre_id,
				}).then(res => {
					this.orderVerification = res.data
				})
			},
			handleBack() {
				uni.navigateBack({
					delta: 1, // 默认值是1，表示返回的页面层数
				});
			},
			handleCopy() {
				uni.setClipboardData({
					data: this.orderVerification.code,
					success: function() {
						uni.showToast({
							title: "复制成功",
						});
					},
					fail: function() {
						console.error("复制失败");
					},
				});
			},
		},
	};
</script>

<style lang="scss">
	.verification-page {
		height: 100%;
		min-height: 100vh;
		background: #f5f5f4;
		padding-bottom: calc(env(safe-area-inset-bottom) / 2);

		.verification-content {
			width: 100%;
			height: 772rpx;
			background: linear-gradient(#a3c616 0%,
					#ddf79a 70%,
					rgba(221, 247, 154, 0) 100%);
			padding: 60rpx 32rpx;
			box-sizing: border-box;
			position: relative;
			z-index: 10;

			.title {
				font-weight: 500;
				font-size: 44rpx;
				color: #ffffff;
				padding-left: 30rpx;
			}

			.small-title {
				font-weight: 400;
				font-size: 26rpx;
				color: #ffffff;
				padding-left: 30rpx;
			}
		}

		.courses-box {
			width: 100%;
			// height: 900rpx;
			background: #fff;
			border-radius: 28rpx;
			margin-top: 20rpx;
			padding-bottom: 54rpx;

			.courses-info {
				width: 100%;
				margin-top: 20rpx;
				padding: 20rpx 22rpx;
				box-sizing: border-box;
				margin-top: 12rpx;
				display: flex;
				border-bottom: 1px #e6e5e5 solid;
				padding-bottom: 26rpx;


				.courses-left {
					width: 108rpx;
					height: 108rpx;
					background: #ffffff;
					border-radius: 28rpx;

					.image {
						width: 108rpx;
						height: 108rpx;
					}
				}

				.courses-right {
					flex: 1;
					min-height: 108rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					margin-left: 18rpx;

					.courses-right-top {
						font-weight: bold;
						font-size: 32rpx;
						display: flex;
						align-items: center;
						justify-content: space-between;
						.courses-price{
							width: 300rpx;
							text-align: right;
						}
					}

					.courses-right-bottom {
						font-size: 28rpx;
						color: #6D7278;
					}
				}
			}

		}

		.please {
			width: 640rpx;
			height: 640rpx;
			background: rgba(163, 198, 22, 0.1);
			border-radius: 28rpx;
			margin: 0 auto;
			text-align: center;

			.perform {
				width: 640rpx;
				height: 104rpx;
				background: #a3c616;
				border-radius: 28rpx 28rpx 0rpx 0rpx;
				line-height: 104rpx;
				text-align: center;
				color: #fff;
				font-size: 32rpx;
			}

			.qrcode {
				width: 296rpx;
				height: 296rpx;
				margin: 68rpx auto;
			}

			.VerCode {
				width: 100%;
				display: flex;
				font-size: 32rpx;
				justify-content: center;
				font-weight: bold;

				.copy {
					color: #a3c616;
					font-size: 32rpx;
					margin-left: 10rpx;
				}
			}
		}

		.back {
			width: 272rpx;
			height: 72rpx;
			border-radius: 36rpx;
			border: 2rpx solid #a3c616;
			font-weight: 400;
			font-size: 28rpx;
			color: #a3c616;
			display: flex;
			align-items: center;
			text-align: center;
			justify-content: center;
			margin: 56rpx auto 0;
		}
	}
</style>